package com.share.domain;

import com.share.common.enums.UserStatus;
import com.share.common.enums.UserStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * security用户
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SecurityUser implements UserDetails {

    private Long id;
    private String username;
    private String password;
    private String jti;
    private String avatar;
    private String nickname;
    private String extraInfo;
    private UserStatus accountNonExpired;
    private UserStatus accountNonLocked;
    private UserStatus  credentialsNonExpired;
    private UserStatus enabled;
    private List<String> roles;
    private List<SimpleGrantedAuthority> authorities;

    /**
     * 用户权限
     * @return 返回用户权限
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    /**
     * 返回用户密码
     * @return 密码
     */
    @Override
    public String getPassword() {
        return this.password;
    }

    /**
     * 返回用户名
     * @return 返回用户名
     */
    @Override
    public String getUsername() {
        return this.username;
    }

    /**
     * 账户是否过期 (true 未过期，false 过期)
     * @return 返回账户是否过期
     */
    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired.getValue();
    }

    /**
     * 账户是否上锁 （true 未锁 ，false 上锁）
     * @return 返回是否上锁
     */
    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked.getValue();
    }

    /**
     * 判断是否过期 （true 未过期 ，false 过期）
     * @return 返回账户是否过期
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired.getValue();
    }

    /**
     * 返回账户是否启用 （true 启用，false 不启用）
     * @return 返回账户是否启用
     */
    @Override
    public boolean isEnabled() {
        return enabled.getValue();
    }
}
